import React from 'react';
import { Col, Button } from 'antd';
import Modal from '../../../../components/Modal/index';
import IndicatorAdd from '../../../Variable/Indicator/add';
import FieldAdd from '../../../Variable/Field/add';
import { randomKey } from '../../../../utils/utils';

export default function OtherBtn(props) {
  let modal = null;
  const open = (title, width, Component) => {
    const modelIds = randomKey();
    modal = Modal.open({
      title: title || '新增',
      width: width || '1000px',
      key: modelIds,
      content: (
        <Component
          modelId={modelIds}
          closeModal={closeModal}
          actionType='add'
          window_time_unit={props.codes.window_time_unit}
        />
      ),
      isOkBtn: false,
      maskClosable: false,
      isCancelBtn: false,
    });
  };

  const closeModal = () => {
    Modal.close(modal);
    props.onComplete && props.onComplete();
  };
  console.log(props);
  return (
    <>
      <Col>
        <Button onClick={() => open('字段', 600, FieldAdd)}>添加字段</Button>
      </Col>
      <Col>
        <Button onClick={() => open('指标', 1000, IndicatorAdd)}>添加指标</Button>
      </Col>
    </>
  );
}
